package com.openbravo.data.loader;

//import B;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Properties;

import javax.imageio.ImageIO;

import com.attilax.util.FileUtils;

public class ImageUtils
{
  private static char[] HEXCHARS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };

  private static byte[] readStream(InputStream paramInputStream)
    throws IOException
  {
//    byte[] arrayOfByte1 = new byte[1024];
//    int i;
//    byte[] arrayOfByte2;
//    for (Object localObject = new byte[0]; (i = paramInputStream.read(arrayOfByte1)) != -1; localObject = arrayOfByte2)
//    {
//    	 byte[] localObject2=(byte[]) localObject;//ati
//      arrayOfByte2 = new byte[localObject2.length + i];
//      System.arraycopy(localObject, 0, arrayOfByte2, 0, localObject2.length);
//      System.arraycopy(arrayOfByte1, 0, arrayOfByte2, localObject2.length, i);
//    }
//    return (byte[])localObject2;
	  return FileUtils.toByteArr(paramInputStream);
  }

  public static byte[] getBytesFromResource(String paramString)
  {
    InputStream localInputStream = ImageUtils.class.getResourceAsStream(paramString);
    if (localInputStream == null)
      return null;
    try
    {
      byte[] arrayOfByte1 = readStream(localInputStream);
      return arrayOfByte1;
    }
    catch (IOException localIOException1)
    {
      byte[] arrayOfByte2 = new byte[0];
      return arrayOfByte2;
    }
    finally
    {
      try
      {
        localInputStream.close();
      }
      catch (IOException localIOException4)
      {
      }
    }
  //  throw localObject;
  }

  public static BufferedImage readImageFromResource(String paramString)
  {
    return readImage(getBytesFromResource(paramString));
  }

  public static BufferedImage readImage(String paramString)
  {
    try
    {
      return readImage(new URL(paramString));
    }
    catch (MalformedURLException localMalformedURLException)
    {
    }
    return null;
  }

  public static BufferedImage readImage(URL paramURL)
  {
    InputStream localInputStream = null;
    try
    {
      URLConnection localURLConnection = paramURL.openConnection();
      localInputStream = localURLConnection.getInputStream();
      BufferedImage localBufferedImage = readImage(readStream(localInputStream));
      return localBufferedImage;
    }
    catch (IOException localIOException1)
    {
      BufferedImage localBufferedImage = null;
      return localBufferedImage;
    }
    finally
    {
      try
      {
        if (localInputStream != null)
          localInputStream.close();
      }
      catch (IOException localIOException4)
      {
    	  try {
			throw localIOException4;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
      }
    }
   
  }

  public static BufferedImage readImage(byte[] paramArrayOfByte)
  {
    if (paramArrayOfByte == null)
      return null;
    try
    {
      return ImageIO.read(new ByteArrayInputStream(paramArrayOfByte));
    }
    catch (IOException localIOException)
    {
    }
    return null;
  }

  public static byte[] writeImage(BufferedImage paramBufferedImage)
  {
    if (paramBufferedImage == null)
      return null;
    try
    {
      ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
      ImageIO.write(paramBufferedImage, "png", localByteArrayOutputStream);
      localByteArrayOutputStream.flush();
      localByteArrayOutputStream.close();
      return localByteArrayOutputStream.toByteArray();
    }
    catch (IOException localIOException)
    {
    }
    return null;
  }

  public static Object readSerializable(byte[] paramArrayOfByte)
  {
    if (paramArrayOfByte == null)
      return null;
    try
    {
      ObjectInputStream localObjectInputStream = new ObjectInputStream(new ByteArrayInputStream(paramArrayOfByte));
      Object localObject = localObjectInputStream.readObject();
      localObjectInputStream.close();
      return localObject;
    }
    catch (ClassNotFoundException localClassNotFoundException)
    {
      return null;
    }
    catch (IOException localIOException)
    {
    }
    return null;
  }

  public static byte[] writeSerializable(Object paramObject)
  {
    if (paramObject == null)
      return null;
    try
    {
      ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
      ObjectOutputStream localObjectOutputStream = new ObjectOutputStream(localByteArrayOutputStream);
      localObjectOutputStream.writeObject(paramObject);
      localObjectOutputStream.flush();
      localObjectOutputStream.close();
      return localByteArrayOutputStream.toByteArray();
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
    }
    return null;
  }

  public static Properties readProperties(byte[] paramArrayOfByte)
  {
    Properties localProperties = new Properties();
    try
    {
      if (paramArrayOfByte != null)
        localProperties.loadFromXML(new ByteArrayInputStream(paramArrayOfByte));
    }
    catch (IOException localIOException)
    {
    }
    return localProperties;
  }

  public static String bytes2hex(byte[] paramArrayOfByte)
  {
    StringBuffer localStringBuffer = new StringBuffer(paramArrayOfByte.length * 2);
    for (int i = 0; i < paramArrayOfByte.length; i++)
    {
      int j = paramArrayOfByte[i];
      localStringBuffer.append(HEXCHARS[((j & 0xF0) >> 4)]);
      localStringBuffer.append(HEXCHARS[(j & 0xF)]);
    }
    return localStringBuffer.toString();
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.data.loader.ImageUtils
 * JD-Core Version:    0.6.0
 */